<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>级联数据列表</title>

    <link href="/Application/Admin/Public/css/base.css" rel="stylesheet">
    <link rel="stylesheet" href="/Application/Admin/Public/custom/uimaker/easyui.css">
    <link rel="stylesheet" type="text/css" href="/Application/Admin/Public/custom/uimaker/icon.css">
    <link rel="stylesheet" href="/Application/Admin/Public/css/providers.css">
    <style>
		#formAdd table{ width:100%;}
		#formAdd table td{ padding:5px;}
		#formAdd table td.td-left{text-align: right; padding-right: 10px;}
		
        input:hover, input:focus { border-color: #C9C9C9; }
    </style>
</head>
<body>
<div class="container" >
    <input type = "hidden" name = "sign" id = "groupsign" val="<?php echo ($sign); ?>">
    <table id="cxdm" style="width:100%;height:564px" title="级联数据列表" data-options="
                rownumbers:true,
                singleSelect:false,
                autoRowHeight:true,
                pagination:true,
                fitColumns:true,
                striped:true,
                checkOnSelect:true,
                selectOnCheck:true,
                collapsible:true,
                toolbar:'#tb',
                pageSize:10">
    </table>
    <div id="DivAdd" class="easyui-dialog" style="width:450px;height:250px;padding:10px 20px"
         closed="true" resizable="true" modal="true" data-options="iconCls: 'icon-add',buttons: '#dlg-buttons'">
        <form id="formAdd" method="post" novalidate="novalidate">
            <input type="hidden" id="action" name="action">
            <input type="hidden" id="id" name="id">
            <table>
				<tr>
					<td class="td-left" width="25%">级联名称:</td>
					<td width="75%"><input class="easyui-textbox" type="text" name="dataname" data-options="required:true" style="height:30px;"></td>
				</tr>
				<tr>
					<td class="td-left">级联数据:</td>
					<td><input class="easyui-textbox" type="text" name="datavalue" data-options="required:true" style="height:30px;"></td>
				</tr>
				<tr>
					<td class="td-left">排序:</td>
					<td><input class="easyui-numberspinner" value="1" name="orderid" data-options="increment:1,required:true" style="height:30px;"></td>
				</tr>
	        </table>
        </form>
    </div>
    <div id="dlg-buttons">
        <div style="text-align:right; padding-top:10px">
            <a href="javascript:void(0)" class="easyui-linkbutton" id="btnAddOK" iconcls="icon-ok" onclick="btnAddOK()">确定</a>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-cancel" onclick="javascript:$('#DivAdd').dialog('close')">关闭</a>
        </div>
    </div>
</div>
<div id="tb" style="padding:0 30px;">

    <div class="opt-buttons">
        <a href="Javascript:history.back();" class="easyui-linkbutton" iconCls="icon-back" >返回</a>
        <a href="#" class="easyui-linkbutton" iconCls="icon-add" onclick = "addCasCasdeData()">新增</a>
        <a href="#" class="easyui-linkbutton" iconCls="icon-edit" onclick = "editCasCasdeData()">修改</a>
    </div>

</div>

<script type="text/javascript" src="/Application/Admin/Public/custom/jquery.min.js"></script>
<script type="text/javascript" src="/Application/Admin/Public/custom/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/Application/Admin/Public/custom/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="/Application/Admin/Public/js/plugins/layer/layer.min.js"></script>






<script type="text/javascript">

    $(document).ready(function(){
        var sign  = "<?php echo ($sign); ?>";
        var level  = "<?php echo ($level); ?>";
        var dataValue  = "<?php echo ($dataValue); ?>";
        loadGrid(sign,level,dataValue);
    });

    //加载表格datagrid
    function loadGrid(sign,level,dataValue)
    {
        //加载数据
        $('#cxdm').datagrid({
            width: 'auto',
            height:$(window).height(),
            autoRowHeight:true,
            striped: true,
            singleSelect :true ,
            fitColumns:true,
            url:'<?php echo U("Cascade/getCasCadeData");?>',
            queryParams:{
                sign:sign,
                level:level,
                datavalue:dataValue,
            },
            frozenColumns:[[//在冻结列中加入多选框
                {field:'chek',checkbox:true}
            ]],
            loadMsg:'数据加载中请稍后……',
            pagination: false,
            rownumbers: true,
            columns:[[
//                {field:'id',align: 'center',checkbox:"false",
//                    formatter:function(val,row,index) {
////                        return "<a href='jsp/proposal/psconsultview.jsp?id=" + rec.adviceid + "'>" + val + "</a>";
//                        return "<input type = 'checkbox' name = 'ck' data-id = '" + val + "' value = '" + val + "'>";
//                    }
//                },
                {field:'id',title: 'ID',align: 'center',sortable:"false",width:50},
//                {field:'dataname',title: '<select id="datasign" data-value = "" onchange="levelData()"></select>',align: 'center',width:"400px"},
                {field:'dataname',title: '级联名称',align: 'center',width:100,
                    formatter:function(val,row,index){
                        return "<a style='text-decoration:none' href = '<?php echo U("Cascade/casCadeData");?>/level/"+(Number(level)+1)+"/value="+row.datavalue+"/sign/"+sign+"'>"+val+"</a>";
                    }},
                {field:'datavalue',title: '级联数据值',align: 'center',width:100},
                {field:'orderid',title: '排序',align: 'center',width:50},
                {field:'operate',title: '操作',align: 'center',width:100,
                    formatter:function(val,row,index){
                        return "<a href = '<?php echo U("Cascade/casCadeData");?>/level/"+(Number(level)+1)+"/value/"+row.datavalue+"/sign/"+sign+"'>查看</a>"
//                     return "<a href = '/Data/casCadeData?id="+row.id+"'>修改</a>";
                    }
                },
            ]],
        });

//       $("#datasign").append('<?php echo ($selectHtml); ?>');
    }

    function reload(){
        $('#cxdm').datagrid('load',{
            score: $("#examscore").val(),
        });
    }

    //删除
    function delAll(){
        if(window.confirm("删除该分类将删除其所有的子分类，确定吗?")){
            return true ;
        }else{
            return false;
        }
    }

    //新增级联数据
    function addCasCasdeData(){
        $("#DivAdd").dialog('open').dialog('setTitle', '新增级联');
        $('#formAdd').form('clear');
        $('#action').val("add");
    }


    //修改
    function editCasCasdeData(id){
        var arr=$('#cxdm').datagrid('getSelections');
        if(!arr[0]){
            $.messager.alert('提示',"请选择一条数据");
            return false;
        }
        $("#DivAdd").dialog('open').dialog('setTitle', '修改级联');
        $('#formAdd').form('load',arr[0]);
        $('#action').val("update");
    }

    //确定提交数据
    function btnAddOK() {
        var sign  = "<?php echo ($sign); ?>";
        var show  = "<?php echo ($show); ?>";
        var level = "<?php echo ($level); ?>"
        var jsonCasData = $("#formAdd").serialize(); //序列化formAdd表单。
        $.ajax({
            url: '<?php echo U("Cascade/addCascadeData");?>', //将表单数据通过异步提交
            type: 'post',
            data: {
                jsonCasData: jsonCasData,
                sign: sign,
                show:show,
                level:level
            },
            success: function (data) {
                //console.log(data)
                if (data.status == 1) {
                    $.messager.alert('提示',data.msg);
                    window.location.reload();
                } else {
                    $.messager.alert('提示',data.msg);
                }

            },
            error: function () {
                $.messager.alert('提示',"数据错误！");
            }
        })
    }
</script>
</body>
</html>